package com.pompom.matchcrawler;

import java.util.HashMap;
import java.util.LinkedList;

import com.pompom.workers.AbstractWorker;

public class MultiInstanceManager {


	private static HashMap<Class, LinkedList<AbstractWorker>> classSet= new HashMap<Class, LinkedList<AbstractWorker>>();
	
	public static void registerMe( AbstractWorker w)
	{
		LinkedList <AbstractWorker> workerList = classSet.get( w.getClass());
		
		if (workerList==null)
		{
			System.out.println("created worker list "+w.getClass());
			workerList = new LinkedList<AbstractWorker>();
			classSet.put(w.getClass(), workerList);
		}
		System.out.println("Added worker "+w);
		workerList.add(w);
		
		
	}
	
	public static int getTotalMod(AbstractWorker w)
	{
		
		LinkedList <AbstractWorker> workerList = classSet.get( w.getClass());
		return workerList.size();
	}
	
	
	public static int getMyDivisor(AbstractWorker w)
	{
	
		LinkedList <AbstractWorker> workerList = classSet.get( w.getClass());
		
		int idx =0;
		
		for (int i=0;i<workerList.size();i++)
		{
			if (workerList.get(i)==w)
				return i;
		}
		return 0;
	
	}
	
}
